package ge.telasi.tasks.ui.user;

import ge.telasi.tasks.model.Group;
import ge.telasi.tasks.ui.UIUtils;
import ge.telasi.tasks.ui.comp.CommonDialog;
import java.awt.Component;

/**
 * @author dimitri
 */
public class GroupPropertiesDialog extends CommonDialog {

    public GroupPropertiesDialog(Component parent) {
        super(parent, true);
        initComponents();
        getRootPane().setDefaultButton(jButton1);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        titlePanel1 = new ge.telasi.tasks.ui.comp.TitlePanel();
        groupPropertiesPanel1 = new ge.telasi.tasks.ui.user.GroupPropertiesPanel();
        lnkGroupContent = new ge.telasi.tasks.ui.comp.Hyperlink();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButton1.setText("გასვლა");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        titlePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons48x48/group.png"))); // NOI18N
        titlePanel1.setSubTitle("გაეცანით ჯგუფის თვისებებს");
        titlePanel1.setTitle("ჯგუფის თვისებები");

        lnkGroupContent.setText("ჯგუფის შემადგენლობა");
        lnkGroupContent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lnkGroupContentMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(titlePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
            .addComponent(groupPropertiesPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnkGroupContent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 189, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(titlePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(groupPropertiesPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(lnkGroupContent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void lnkGroupContentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lnkGroupContentMouseClicked
        showGroupContent();
    }//GEN-LAST:event_lnkGroupContentMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ge.telasi.tasks.ui.user.GroupPropertiesPanel groupPropertiesPanel1;
    private javax.swing.JButton jButton1;
    private ge.telasi.tasks.ui.comp.Hyperlink lnkGroupContent;
    private ge.telasi.tasks.ui.comp.TitlePanel titlePanel1;
    // End of variables declaration//GEN-END:variables

    public void setGroup(Group group) {
        groupPropertiesPanel1.setGroup(group);
        setTitle(group.getName() + " -- თვისებები");
    }

    public Group getGroup() {
        return groupPropertiesPanel1.getGroup();
    }

    private void showGroupContent() {
        GroupUserDialog dialog = new GroupUserDialog(this);
        dialog.setGroup(getGroup());
        UIUtils.openDialog(dialog);
    }

}
